﻿//
// Created by francklinson on 2021/3/31.
//

#ifndef CPPPRIMERPLUSREADINGCODES_EMP_H
#define CPPPRIMERPLUSREADINGCODES_EMP_H


// emp.h -- header file for abstr_emp class and children

#include <iostream>
#include <string>

// 抽象基类
class abstr_emp
{
private:
    std::string fname;   // abstr_emp's first name
    std::string lname;   // abstr_emp's last name
    std::string job;     // 工作

public:
    abstr_emp() : fname("none"), lname("none"), job("none")
    {};

    abstr_emp(const std::string &fn, const std::string &ln,
              const std::string &j);

    virtual void ShowAll() const; // labels and shows all data
    virtual void SetAll();        // prompts user for values
    friend std::ostream &operator<<(std::ostream &os, const abstr_emp &e);

    // just displays first and last name
    virtual ~abstr_emp() = 0;     // virtual base class  纯虚函数
};

// 员工类
class employee : public abstr_emp
{
public:
    employee() : abstr_emp()
    {};

    employee(const std::string &fn, const std::string &ln,
             const std::string &j) : abstr_emp(fn, ln, j)
    {};

    void ShowAll() const override;

    void SetAll() override;

    ~employee() override;
};

// 经理类
class manager : virtual public abstr_emp
{
private:
    int inchargeof; // number of abstr_emps managed
protected:
    int InChargeOf() const
    { return inchargeof; } // output
    int &InChargeOf()
    { return inchargeof; }      // input
public:
    manager()
    {
        inchargeof = 0;
    };

    manager(const std::string &fn, const std::string &ln,
            const std::string &j, int ico = 0) : abstr_emp(fn, ln, j), inchargeof(ico)
    {};

    manager(const abstr_emp &e, int ico) : abstr_emp(e), inchargeof(ico)
    {};

    manager(const manager &m); // 复制构造

    void ShowAll() const override;

    void SetAll() override;
};

class fink : virtual public abstr_emp
{
private:
    std::string reportsto; // to whom fink reports
protected:
    const std::string ReportsTo() const
    { return reportsto; }

    std::string &ReportsTo()
    { return reportsto; }

public:
    fink()
    {
        reportsto = "none";
    };

    fink(const std::string &fn, const std::string &ln,
         const std::string &j, const std::string &rpo) : abstr_emp(fn, ln, j), reportsto(rpo)
    {};

    fink(const abstr_emp &e, const std::string &rpo) : abstr_emp(e), reportsto(rpo)
    {};

    fink(const fink &e);

    void ShowAll() const override;

    void SetAll() override;
};

class highfink : public manager, public fink // management fink
{
public:

    highfink() : manager(), fink()
    {};

    highfink(const std::string &fn, const std::string &ln,
             const std::string &j, const std::string &rpo,
             int ico) : manager(fn, ln, j, ico), fink(fn, ln, j, rpo)
    {};

    highfink(const abstr_emp &e, const std::string &rpo, int ico) : manager(e, ico), fink(e, rpo)
    {};

    highfink(const fink &f, int ico) : abstr_emp(f), fink(f), manager(f,
                                                                      ico) // 由于使用虚继承，abstr_emp的内容不会被fink和manager传递到abstr_emp，必须显式进行初始化，否则将调用abstr_emp的默认构造函数
    {};

    highfink(const manager &m, const std::string &rpo) : abstr_emp(m), manager(m), fink(m, rpo)
    {};

    highfink(const highfink &h) : manager(h), fink(h)
    {};

    void ShowAll() const override;

    void SetAll() override;
};


#endif //CPPPRIMERPLUSREADINGCODES_EMP_H
